package part1.language_basis.day06;

import java.util.Arrays;

//数组的演示
public class ArrayDemo {
    public static void main(String[] args) {

        //6)数组的复制：
        /** 数组的扩容 */
        /*
        int[] a = {10,20,30,40,50};
        a = Arrays.copyOf(a,a.length+1);
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
         */

        /** 有返回值 要用数组接收 目标数组长度可以随便不会报错
         * 若长度大于源数组  则会在后面补默认值0
         * 若长度小于源数组  则会把原数组后面的元素截掉*/
        int[] a = {10,20,30,40,50};
        //a：源数组
        //b：目标数组
        //6：目标数组b的长度
        int[] b = Arrays.copyOf(a,6);
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }


        /**下标位置和长度要保证两个数组都能取到数或者不能超  否则会报数组下标越界异常*/
        /*
        int[] a = {10,20,30,40,50};
        int[] b = new int[6]; //0,0,0,0,0,0
        //a: 源数组
        //1: 源数组的起始下标
        //b: 目标数组
        //2：目标数组的起始下标
        //3：要复制的元素个数
        System.arraycopy(a,1,b,2,3);
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

         */
    }
}
